//
//  H5Container.m
//  UpdateDemo
//
//  Created by 袁伟森 on 2019/3/18.
//  Copyright © 2019 Alibaba. All rights reserved.
//

#import "H5Container.h"
#import "H5ViewController.h"
#import "MPWebView.h"
@implementation H5Container


+ (void)configNebulaSDK
{
    
    // 控件创建
    [NBServiceConfigurationGet() setViewControllerClass:[H5ViewController class]];
    [NBServiceConfigurationGet() setContentViewClass:[MPWebView class]];
    
    // 自定义的插件配置，所有自定义的jsapi和plugin都保存在DemoPresetApps.bundle/Poseidon-Extra-Config.plist中
    //    NSString *filePath = [[NSBundle mainBundle].bundlePath stringByAppendingFormat:@"/%@/%@", @"DemoPlugins.bundle", @"Poseidon-Extra-Config.plist"];
    //    [NBServiceConfigurationGet() setExtraPluginsFilePath:filePath];
    
    // 预置包配置，所有预置的离线包在DemoPresetApps.bundle中，预置的包信息在 DemoPresetApps.bundle/NAMApplist.plist 中
    [NBServiceConfigurationGet().appConfig setPresetApplistPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"DemoPresetApps.bundle/NAMApplist.plist"] ofType:nil]];
    [NBServiceConfigurationGet().appConfig setPresetAppPackagePath:[[NSBundle mainBundle] pathForResource:@"DemoPresetApps.bundle" ofType:nil]];
    
    // 包管理服务器配置
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"Product Version"];
    [NBServiceConfigurationGet() setClientVersion:version];
    NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
    [NBServiceConfigurationGet() setClientBundleId:bundleId];
    [NBServiceConfigurationGet() setUserAgent:[NSString stringWithFormat:@"UpdateDemo %@", version]];//指定userAgent
    
    [NBServiceConfigurationGet() setCommonResourceAppList:@[@"12345678"]];  //指定应用的全局资源包
    // 离线包管理设置（验签公钥、公共资源包、离线包下载器）
    NSString *pubpem = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"pem"];
    [NBServiceConfigurationGet().appConfig setSignPublicKey: [NSString stringWithContentsOfFile:pubpem encoding:NSUTF8StringEncoding error:nil]];// 设置离线包验签公钥
    [NBServiceConfigurationGet() setIsNeed2VerifyApp:NO];//关闭验签，上述设置公钥不生效
    [NBServiceConfigurationGet().appConfig setRequestManager:[NARequestManager sharedInctance]]; // 设置离线包下载器
    NAMServiceGet();
    [NBServiceGet() start];
}
@end
